/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

(function($){
    $.fn.arraytextfield = function(options) {

 var defaults = {
            event: 'change',
            container: 'div'
        };
        var myoptions = $.extend(defaults, options);

        return this.each(function() {
            var copy = $(this);
            var container = $(this).parent(myoptions.container)
            var controls = $(this).find("input");
            controls.live(myoptions.event, function(){
                g=false;
                $(copy).find("input").each(function()
                {
                    if($(this).val() =="")
                    {
                        g=true;
                    }
                }
                );
                if(g==false) {
                    $(copy).clone().appendTo(container);
                    $(container).children('div:last').children('input').val('');
                }
            }
            );
            body.append('<div id="control_button" class="ui-widget ui-state-default ui-corner-right control"><a class="ui-state-default ui-corner-all" href="javascript:void(0);"><span class="ui-icon '+myoptions.icon+'" style=""></span></a></div>');
            control.focus(function(){
                $('.control > a').click(myoptions.click);
                $('.control').css('left',control.offset().left+control.outerWidth()-3);
                $('.control').css('top',control.offset().top-3);
                $('.control').show('slide',{
                    direction:'left'
                },1000);
            }
            );
            control.blur(function(){
                $('.control').hide('slide',1000);
            }
            );

        });
    };
})(jQuery);